package com.jmcgg.freesky.common.util;

import java.util.Vector;

/**
 * Title: FreeSky Common Java Library <br>
 * Description: FreeSky Common Java Library <br>
 * Copyright: Copyright (c) 2005~2009 www.afss.cn <br>
 * Company: Amei's FreeSky Studio <br>
 * 
 * @author <b>Jacky Chou</b> (AFSS [Amei's FreeSky Studio])
 * @version 1.2.1, 2008-08-05, Clean and optimize the source code.<br>
 *          1.2.0, 2008-02-23, Upgrade freesky.jar to 1.2.0 with Struts 2<br>
 *          1.0.0, 2006-05-30, Initial Version
 */
public class NameValueUtil extends FreeskyUtil {
	public NameValueUtil() {
	}

	/**
	 * ���ƥ��Ե�ֵ��Vector��Ѱ�Ҷ�Ӧ�����
	 * 
	 * @param Vector
	 * @param int
	 * @return
	 */
	public String findName(Vector<?> vect, int value) {
		if (vect == null) {
			return "unknown";
		}
		for (int i = 0; i < vect.size(); i++) {
			if (((NameValueIntBean) vect.get(i)).getValue() == value) {
				return ((NameValueIntBean) vect.get(i)).getName();
			}
		}
		return "unknown";
	}

	public String findName(Vector<?> vect, String value) {
		if (vect == null) {
			return "unknown";
		}
		for (int i = 0; i < vect.size(); i++) {
			if (((NameValueStringBean) vect.get(i)).getValue().equals(value)) {
				return ((NameValueStringBean) vect.get(i)).getName();
			}
		}
		return "unknown";
	}

	public int findIntValue(Vector<?> vect, String name) {
		if (vect == null) {
			return -1;
		}
		for (int i = 0; i < vect.size(); i++) {
			if (((NameValueIntBean) vect.get(i)).getName().equals(name)) {
				return ((NameValueIntBean) vect.get(i)).getValue();
			}
		}
		return -1;
	}

	public String findStrValue(Vector<?> vect, String name) {
		if (vect == null) {
			return "null";
		}
		for (int i = 0; i < vect.size(); i++) {
			if (((NameValueStringBean) vect.get(i)).getName().equals(name)) {
				return ((NameValueStringBean) vect.get(i)).getValue();
			}
		}
		return "null";
	}

}
